﻿using System.Collections.Generic;
using System.Linq;
using LBoL.Base;
using LBoL.ConfigData;
using LBoL.Core;
using LBoL.Core.Battle;
using LBoL.Core.Battle.BattleActions;
using LBoL.Core.Battle.Interactions;
using LBoL.Core.Cards;
using LBoL.Core.StatusEffects;
using LBoL.EntityLib.Cards.Character.Cirno;
using LBoL.EntityLib.StatusEffects.Enemy;
using LBoLEntitySideloader.Attributes;
using ProbeMod.Cards.Template;
using ProbeMod.StatusEffects;

namespace ProbeMod.Cards
{
    public sealed class ProbeIRobotDef : ProbeCardTemplate
    {
        public override CardConfig MakeConfig()
        {
            CardConfig config = GetCardDefaultConfig();

            config.Rarity = Rarity.Uncommon;
            config.Type = CardType.Ability;
            config.TargetType = TargetType.Nobody;

            config.Colors = new List<ManaColor>() { ManaColor.White };
            config.Cost = new ManaGroup() { White = 1, Any = 1 };
            config.UpgradedCost = new ManaGroup() { White = 1, Any = 1 };

            config.Value1 = 2;  // 自动护盾值
            config.Value2 = 4;  

            config.RelativeEffects = new List<string> { "DroneBlock", "Appliance" };
            config.UpgradedRelativeEffects = new List<string> { "DroneBlock", "Appliance" };

            config.Index = CardIndexGenerator.GetUniqueIndex(config);
            return config;
        }
    }

    /// <summary>
    /// 机械单位
    /// 获得3/5自动护盾和家用电器
    /// </summary>
    [EntityLogic(typeof(ProbeIRobotDef))]
    public sealed class ProbeIRobot : ProbeCard
    {
        public int Level => IsUpgraded ? Value2 : Value1;

        protected override IEnumerable<BattleAction> Actions(UnitSelector selector, ManaGroup consumingMana, Interaction precondition)
        {
            if (Battle.Player.HasStatusEffect<Weak>())
            {
                yield return new RemoveStatusEffectAction(Battle.Player.StatusEffects.Where(s => s is Weak).ToList().FirstOrDefault());
            }
            if (Battle.Player.HasStatusEffect<Vulnerable>())
            {
                yield return new RemoveStatusEffectAction(Battle.Player.StatusEffects.Where(s => s is Vulnerable).ToList().FirstOrDefault());
            }

            yield return BuffAction<DroneBlock>(level: Level);
            yield return BuffAction<Appliance>(level:1);
        }
    }
}
